import * as XLSX from "xlsx"

export const readExcel = (file) => {
    return new Promise((resolve,reject) => {
        try {
            //获取上传对象
            const fileReader = new FileReader();
            fileReader.onload = (event) => {
                const fileData = event.target.result
                //读取excel文件
                const workboot = XLSX.read(fileData,{
                    type:"binary",
                })
                //默认读取第一个sheet
                let sheel0 = workboot.SheetNames[0]
                let blockArr = XLSX.utils.sheet_to_json(workboot,sheel0)
                resolve(blockArr)
            }
            fileReader.readAsBinaryString(file)
        }catch(e){
            reject(e)
        }
    })
}